<template>
  <div class="page-container">
    <div class="control-container">
      <div class="right-panel">
        <div class="search-panel">
          <el-form :inline="true" label-width="100">
            <el-form-item label="开始时间">
              <el-date-picker
                v-model="query.startTime"
                type="datetime"
                placeholder="选择日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                :clearable="true"
              />
            </el-form-item>
            <el-form-item label="结束时间">
              <el-date-picker
                v-model="query.endTime"
                type="datetime"
                placeholder="选择日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                :clearable="true"
              />
            </el-form-item>
            <el-form-item label="打卡目的：">
              <el-select v-model="query.objective" filterable clearable placeholder="请选择">
                <el-option
                  v-for="item in objectives"
                  :key="'selectEngineerName'+'_'+item"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </el-form-item>
            <el-button type="primary" @click="handleSelect">查询</el-button>
          </el-form>
        </div>
        <div class="table-panel">
          <el-table
            v-loading="tableLoading"
            class="grid-data-table"
            height="calc(100vh - 300px)"
            :data="tableData"
          >
            <el-table-column align="center" type="index" width="80" />
            <el-table-column prop="engineerName" label="打卡人" />
            <el-table-column prop="enterpriseName" label="企业名称" />
            <el-table-column prop="objective" label="打卡目的" />
            <el-table-column prop="startTime" label="开始时间" />
            <el-table-column prop="endTime" label="结束时间" />
          </el-table>
          <div class="pagination-container">
            <Pagination
              v-show="query.total>0"
              :total="query.total"
              :page.sync="query.page"
              :limit.sync="query.limit"
              @pagination="initData"
            />
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getDict } from '@/utils/dict'
import { enterpriseList } from '@/api/clock/clock'
import { hasBtnPermission as hasBtn } from '@/utils/buttons'
import { getDictLabel, parseTime } from '@/utils'

export default {
  name: 'SituationClock',
  components: {
    Pagination
  },
  data() {
    return {
      tableLoading: false,
      query: {
        page: 1, limit: 20, total: 0,
        resourceName: null, resourceType: null
      },
      tableData: [],
      objectives: ['巡检', '标定', '校准', '故障维修', '其他'],
      dialogVisible: false,
      reportDialogVisible: false,
      dialogType: 'detail',
      resourceTypes: [],
      obj: null,
      previewDialogVisible: false,
      type: ''
    }
  },
  created() {
    this.resourceTypes = getDict('e028')
    this.initData()
  },
  methods: {
    getDictLabel, parseTime, hasBtn,
    initData() {
      const query = JSON.parse(JSON.stringify(this.query))
      this.tableLoading = true
      enterpriseList(query).then(result => {
        this.tableLoading = false
        this.tableData = result.data.list
        this.query.total = result.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 查询
    handleSelect() {
      this.query.page = 1
      this.initData()
    },
    flushPage() {
      this.clearQuery()
      this.initData()
    },
    clearQuery() {
      this.query = {
        page: 1, limit: 10, total: 0,
        resourceName: null, resourceType: null
      }
    },
    closeDialog() {
      this.dialogVisible = false
      this.reportDialogVisible = false
      this.previewDialogVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.download{
  margin: 0px 8px 4px 8px !important;
}
</style>
